require(["common", "coAjax", "hash_routie", "queryString"], function(o, co, n, s) {
	n.on("collection", function() {
		var q = new s(location.hash);
		var t = q.get("type");
		if (t == 2) {
			App.set('title', '商品收藏');
			App.set('f', 'focus');
			co.get(appConfig.user.collect_detail, function(result) {
				App.set("$Cache.user.collect_detail", result.result);
			}, function(c, x, m) {
				alert("error", m);
			});
		} else {
			App.set('title', '店铺收藏');
			App.set('f', '');
			co.get(appConfig.user.collectBus_with_goods_info, function(o) {
				App.set("$Cache.user.collectBus_with_goods_info", o.result)
			}, function(c, x, m) {
				alert("error", m);
			})
		};
		App.set("$Event.remove_goods_from_collect", function(e, vm) {
			co["delete"](appConfig.user.collect_remove, {
				goods_id: vm.get("_id")
			}, function(result) {
				alert("成功把商品取消收藏");
				vm.removeFromArray();
			}, function(errorCode, xhr, errorMsg) {
				alert("error", errorMsg);
			});
		});

		App.set("$Event.user.collect_goods_add_to_cart", function(e, vm) {
			var cart_item = {
				goods_id: vm.get("_id"),
				num: 1
			};
			co.post(appConfig.user.cart, cart_item, function _get_cart_success(result) {
				alert("success", "添加成功")
			}, function(errorCode, xhr, errorMsg) {
				alert("error", errorMsg);
			});

		});

		App.set("$Event.user.remove_collect_bus", function(e, vm) {
			co["delete"](appConfig.user.collectBus_remove, {
				bus_id: vm.get("_id")
			}, function(result) {
				alert("success", "已经取消收藏");
				// _load_collect_bus();
				vm.removeFromArray();
				_load_collect_bus();
			}, function(errorCode, xhr, errorMsg) {
				alert("error", errorMsg)
			});
		});

		function _load_collect_bus() {
			co.get(appConfig.user.collectBus_with_goods_info, function(result) {
				App.set("$Cache.user.collectBus_with_goods_info", result.result);
			}, function(errorCode, xhr, errorMsg) {
				alert("error", errorMsg);
			});
		}
	})
});